#include "mixerbutton.h"
#include "dm/dmdef.h"

MixerButton::MixerButton(const uint8_t out, const uint8_t mus, QWidget *parent)
    : MultiWidget{0, 0, MIXER_VOL_MIN, MIXER_VOL_MAX, LABEL_DECIBEL_UINT, parent}
    , m_out{out}
    , m_mus{mus}
{
    // setCheckable(true);
    // setFixedSize(100, 30);
    // spinBox = new OffSpinBox(OffSpinBox::Min, tr(LABEL_DECIBEL_UINT), this);
    // spinBox->setFixedSize(60, 20);

    // auto layout = new QHBoxLayout(this);
    // layout->setContentsMargins(0, 0, 0, 0);

    // layout->addWidget(spinBox);

    // spinBox->setRange(MIXER_VOL_MIN, MIXER_VOL_MAX);

    // connect(spinBox, QOverload<int>::of(&ASpinBox::valueChanged), this, [=](const int &value) {
    //     setChecked(value != MIXER_VOL_MIN);
    //     emit stateChanged(m_out, m_mus, value - MIXER_VOL_MIN);
    // });
    // connect(this, &QPushButton::toggled, this, [=](bool checked) {
    //     if (checked) {
    //         if (spinBox->value() == MIXER_VOL_MIN) {
    //             spinBox->setValue(MIXER_VOL_MAX);
    //         }
    //     } else {
    //         spinBox->setValue(MIXER_VOL_MIN);
    //     }
    // });
    connect(this, &MultiWidget::valueChanged, this, [=](double value) {
        emit stateChanged(m_out, m_mus, value - MIXER_VOL_MIN);
    });
}

void MixerButton::set(uint8_t vol)
{
    blockSignals(true);
    // spinBox->setValue(static_cast<int>(vol) + MIXER_VOL_MIN);
    // setChecked(vol != 0);
    MultiWidget::set(static_cast<double>(vol) + MIXER_VOL_MIN);
    blockSignals(false);
}
